import {createAction} from 'redux-actions';
import {POST_AUTH_LOGIN, POST_AUTH_BIND, POST_AUTH_PHONE_LOGIN} from './../constants/actionTypes'
import * as authApi from './../apis/auth'

export const login = createAction(POST_AUTH_LOGIN, async(params)=>{
  return await authApi.login(params)
    .then((data) =>{
      if (data){
        return data
      }
      throw 'loginError'
    })
}, (params)=>{
  return {
    ...params,
    sync: 'login'
  }
})


export const userBind = createAction(POST_AUTH_BIND, async(params)=>{
  return await authApi.bind(params)
    .then((data) =>{
      if (data){
        return data
      }
      throw 'bindError'
    })
}, (params)=>{
  return {
    ...params,
    sync: 'bind'
  }
})

export const phoneLogin = createAction(POST_AUTH_PHONE_LOGIN, async(params)=>{
  return await authApi.phoneLogin(params)
    .then((data) =>{
      if (data){
        return data
      }
      throw 'phoneLoginError'
    })
}, (params)=>{
  return {
    ...params,
    sync: 'phoneLogin'
  }
})